<template>
  <basic-container>
    <div class="avue-crud">
      <!-- 搜索工作栏 -->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="客户姓名" prop="customerName">
          <el-input v-model="queryParams.customerName" placeholder="请输入姓名" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="票号" prop="ticketNo">
          <el-input v-model="queryParams.ticketNo" placeholder="请输入票号" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 操作工具栏 -->
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <!-- 列表 -->
      <el-table v-loading="loading" :data="list" style="width: 100%">
        <el-table-column label="编号" align="center" prop="orderId"/>
        <el-table-column label="票号" align="center" prop="ticketNo"/>
        <el-table-column label="客户姓名" align="center" prop="customerName"/>
        <el-table-column label="客户证件号码" align="center" prop="customerIdNo"/>
        <el-table-column label="客户联系方式" align="center" prop="customerPhone"/>
        <el-table-column label="队列名称" align="center" prop="queueName"/>
        <el-table-column label="取号机名称" align="center" prop="ticketMachineName"/>
        <el-table-column label="取号状态" align="center" prop="ticketStatus">
          <template slot-scope="scope">
            <dict-tag :type="DICT_TYPE.TICKET_STATUS" :value="scope.row.ticketStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="更新时间" align="center" prop="updateTime">
          <template slot-scope="scope">
            <span>{{ scope.row.updateTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)"
                       v-if="permissions.business_ticket_order_view">查看
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                       v-if="permissions.business_ticket_order_del">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 对话框(添加 / 修改) -->
      <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
        <el-form ref="form" :model="form" label-width="130px">
          <el-form-item label="票号" prop="ticketNo">
            <el-input v-model="form.ticketNo" :disabled="true"/>
          </el-form-item>
          <el-form-item label="业务编码" prop="businessId">
            <el-input v-model="form.businessId" :disabled="true"/>
          </el-form-item>
          <el-form-item label="客户姓名" prop="customerName">
            <el-input v-model="form.customerName" :disabled="true"/>
          </el-form-item>
          <el-form-item label="客户证件号码" prop="customerIdNo">
            <el-input v-model="form.customerIdNo" :disabled="true"/>
          </el-form-item>
          <el-form-item label="客户联系方式" prop="customerPhone">
            <el-input v-model="form.customerPhone" :disabled="true"/>
          </el-form-item>
          <el-form-item label="窗口名" prop="windowName">
            <el-input v-model="form.windowName" :disabled="true"/>
          </el-form-item>
          <el-form-item label="队列标识" prop="queueKey">
            <el-input v-model="form.queueKey" :disabled="true"/>
          </el-form-item>
          <el-form-item label="队列名称" prop="queueName">
            <el-input v-model="form.queueName" :disabled="true"/>
          </el-form-item>
          <el-form-item label="取号机名称" prop="ticketMachineName">
            <el-input v-model="form.ticketMachineName" :disabled="true"/>
          </el-form-item>

          <el-form-item label="取号时间" prop="ticketPrintTime">
            <el-input v-model="form.ticketPrintTime" :disabled="true"/>
          </el-form-item>
          <el-form-item label="叫号时间" prop="ticketCallTime">
            <el-input v-model="form.ticketCallTime" :disabled="true"/>
          </el-form-item>
          <el-form-item label="离开时间" prop="leaveTime">
            <el-input v-model="form.leaveTime" :disabled="true"/>
          </el-form-item>

          <el-form-item label="过号时间" prop="leaveTime">
            <el-input v-model="form.passTime" :disabled="true"/>
          </el-form-item>
        </el-form>

      </el-dialog>
      <!-- 分页组件 -->
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
                  @pagination="getList"/>
    </div>
  </basic-container>
</template>

<script>
import {mapGetters} from "vuex";
import {fetchList, delObj, getObj} from "@/api/queue/ticketorder"

export default {
  name: "index",
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 结果集合
      list: [],
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        customerName: null,
        ticketNo: null
      }
    }
  },
  created() {
    this.getList()
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  methods: {
    // 查询队列列表
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      fetchList(params).then(res => {
        this.list = res.data.data.records;
        this.total = res.data.data.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.orderId;
      this.$confirm('是否确认删除用编号为"' + row.orderId + '"的数据项?').then(function () {
        return delObj(id);
      }).then(() => {
        this.getList();
        this.$message.success("删除成功");
      }).catch(() => {
      });
    },
    handleDetail(row) {
      this.open = true;
      this.title = "票号详情",
        getObj(row.orderId).then(res => {
          this.form = res.data.data;
        })
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        windowName: undefined,
        windowDescribe: undefined,
      };
      this.resetForm("form");
    },
  }
}
</script>

<style scoped>

</style>
